<?php $this->_extends('_layouts/admin/main_layout'); ?>

<?php $this->_block('resource'); ?>

<?php $this->_endblock(); ?>

<?php $this->_block('title'); ?>
	Jquery Plugins
<?php $this->_endblock(); ?>

<?php $this->_block('contents'); ?>

<div id="content" class="box">
	<h1>添加Jquery插件</h1>
	
	<div id="menu" class="box">
		<ul class="box">
			<li><a href="<?php echo url('adminjqueryplugins/index');?>"><span>返回列表</span></a></li>
		</ul>
	</div>
	
	<fieldset>
		<legend>编写</legend>
		
		<ul class="formErrors">
			<?php $formErrors = $jqPlugins->getValidateError(); if(!empty($formErrors)): ?>
				<?php foreach($formErrors as $item => $errors): ?>
					<li>
						<?php echo $item; ?>
						<ul>
							<?php foreach($errors as $error): ?>
								<li class="error"><?php echo $error; ?></li>
							<?php endforeach; ?>
						</ul>
					</li>
				<?php endforeach; ?>
			<?php endif; ?>
		</ul>
		<form id="jqplugin-addform" enctype="multipart/form-data" method="post" action="<?php echo url('adminjqueryplugins/add'); ?>">
			<table class="nostyle" style="width: 90%;">
				<tr>
					<th style="width: 10%;"></th>
					<th style="width: 90%;"></th>
				</tr>
				<tr>
					<td>插件名称:</td>
					<td><input type="text" class="input-text" name="form[name]" value="<?php echo isset($jqPlugins->attributes['name']) ? $jqPlugins->attributes['name'] : '';?>" /></td>
				</tr>
				<tr>
					<td>文件存放根目录名称:</td>
					<td><input type="text" class="input-text" name="form[root_foldername]" value="<?php echo isset($jqPlugins->attributes['root_foldername']) ? $jqPlugins->attributes['root_foldername'] : '';?>" /></td>
				</tr>
				<tr>
					<td>
						描述:<br /><br />
						可用变量:(<br />
							<?php 
								foreach($jqPlugins->descriptionVars as $name => $desc){
									echo $name . ': ' . $desc . '<br />';
								}
							?>
						<br />)
					
					</td>
					<td><textarea name="form[description]" id="jq-plugin-desc"></textarea></td>
				</tr>
				<tr class="attach-line">
					<td>附件:</td>
					<td>
						<input type="file" class="input-text" name="form[attachment][]" />
						<a href="javascript: void(0);" class="cancel-attach">取消附件</a>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<input type="button" id="add-attach-btn" value="添加附件" />
					</td>
				</tr>
				<tr>
					<td>缩略图:</td>
					<td><input type="file" class="input-text" name="form[thumbnail]" value="" /></td>
				</tr>
				<tr>
					<td>下载包:</td>
					<td><input type="file" class="input-text" name="form[download_pack]" /></td>
				</tr>
				<tr>
					<td colspan="2" class="t-right"><input type="submit" class="input-submit" value="添加"/></td>
				</tr>
			</table>

		</form>
		<!-- 
		<script src="/ckeditor/ckeditor.js"></script>
		<script src="/ckfinder/ckfinder.js"></script>
		<script>
			function insertHTML(editor, insertValue)
			{
				if (editor.mode != 'wysiwyg'){
					editor.setMode('wysiwyg');
					alert('对不起，必须在编辑模式下进行插入操作!');
				}else{
					editor.insertHtml(insertValue);
				}
			}
		
			var jqpluginEditor = CKEDITOR.replace('jq-plugin-desc', {
				skin: 'kama',
				width: '100%',
				height: 300,

		        filebrowserImageBrowseUrl: '/ckfinder/ckfinder.html?Type=Images',
		        filebrowserImageUploadUrl: '/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
		        tabSpaces: 4,
			});
			CKFinder.SetupCKEditor( jqpluginEditor, '/ckfinder/' );
			
		</script> 
		<?php 
//			Q::loadFile('ckeditor_php5.php', Helper_Dir);
//			$CKEditor = new CKEditor();
//			$CKEditor->basePath = '/ckeditor/';
//			$CKEditor->config['filebrowserImageUploadUrl'] = url('/ckeditor/upload');
//			$CKEditor->replace('jq-plugin-desc');
		?>
		-->
		<script type="text/javascript" src="/markitup/jquery.markitup.js"></script>
		<script type="text/javascript" src="/markitup/sets/default/set.js"></script>
		<link rel="stylesheet" type="text/css" href="/markitup/skins/markitup/style.css" />
		<link rel="stylesheet" type="text/css" href="/markitup/sets/default/style.css" />
		<script type="text/javascript">
			var str = '<script>aaa<\/script>'
			$('#jq-plugin-desc').markItUp(mySettings).val(<?php echo isset($jqPlugins->attributes['description']) ? json_encode($jqPlugins->attributes['description']) : '';?>);
		</script>

		
		<script>
			$('#add-attach-btn').data('oriLine', $('.attach-line').first().htmlCode());
		
			$('#add-attach-btn').click(function(){
				var newLine = $(this).data('oriLine');
				$(newLine).find('input').val('');
				$(this).parent().parent().before($(newLine));
			});

			$('.cancel-attach').live('click', function(){
				$(this).parent().parent('tr').remove();
			});
		</script>
	</fieldset>
</div>
<?php $this->_endblock(); ?>